package com.frinder.data.domain.web;

import com.frinder.base.global.Result;
import com.frinder.base.global.ResultGenerator;
import com.frinder.base.db.PageWrapper;
import com.frinder.base.db.ModelWrapper;
import com.frinder.data.domain.model.MapCells;
import com.frinder.data.domain.service.IMapCellsService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;

/**
* Created by frinder on 2019/09/29.
*/
@RestController
@RequestMapping("/mapCells")
public class MapCellsController {
    @Resource
    private IMapCellsService mapCellsService;

    @ApiOperation(value = "添加 MapCells")
    @PostMapping("/add")
    public Result add(@RequestBody MapCells mapCells) {
        mapCellsService.save(mapCells);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 id 删除 MapCells")
    @GetMapping("/delete")
    public Result delete(@RequestParam Long id) {
        mapCellsService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 ids 批量删除 MapCells")
    @GetMapping("/deleteByIds")
    public Result deleteByIds(@RequestParam String ids) {
        mapCellsService.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "更新 MapCells")
    @PostMapping("/update")
    public Result update(@RequestBody MapCells mapCells) {
        mapCellsService.update(mapCells);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 id 查询 MapCells")
    @GetMapping("/detail")
    public Result detail(@RequestParam Long id) {
        MapCells mapCells = mapCellsService.findById(id);
        return ResultGenerator.genSuccessResult(mapCells);
    }

    @ApiOperation(value = "按条件查询 MapCells")
    @PostMapping("/listByModelWrapper")
    public Result listByModelWrapper(@RequestBody ModelWrapper<MapCells> wrapper) {
        List<MapCells> list = mapCellsService.findByModelWrapper(wrapper);
        return ResultGenerator.genSuccessResult(list);
    }

    @ApiOperation(value = "按条件分页查询 MapCells")
    @PostMapping("/page")
    public Result page(@RequestBody PageWrapper<MapCells> page) {
        PageInfo pageInfo = mapCellsService.page(page);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
